import requests
from bs4 import BeautifulSoup
import json

# 创建会话对象，保持登录状态
session = requests.Session()

# 登录URL
login_url = "https://web3.isolarcloud.com.cn/api/login"  # 假设的API端点
# 或者使用表单提交方式
login_page_url = "https://web3.isolarcloud.com.cn/#/login"

# 登录凭证
credentials = {
    "username": "15180036081",
    "password": "Cyf15070123978"
}

# 设置请求头
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
    "Content-Type": "application/json"
}

# 执行登录
try:
    # 方法1: JSON API登录
    response = session.post(login_url, json=credentials, headers=headers)

    # 方法2: 表单登录（如果需要先获取页面）
    # login_response = session.post(login_url, data=credentials, headers=headers)

    if response.status_code == 200:
        print("登录成功")

        # 获取目标数据页面
        data_url = "https://web3.isolarcloud.com.cn/api/data"  # 替换为实际数据接口
        data_response = session.get(data_url, headers=headers)

        if data_response.status_code == 200:
            # 解析JSON数据
            data = data_response.json()
            print("获取数据成功:", data)

            # 或者解析HTML内容
            # soup = BeautifulSoup(data_response.text, 'html.parser')
            # content = soup.find('div', class_='data-content')

    else:
        print(f"登录失败，状态码: {response.status_code}")

except Exception as e:
    print(f"请求出错: {e}")
